package com.lenovo.lcdm.type.controller;

import com.lenovo.lcdm.type.dto.AttributeGroupDTO;
import com.lenovo.lcdm.type.service.TypeAttributeGroupService;
import com.lenovo.lcdm.common.model.ResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther xujing30
 * @Date 2024/01/17
 * @Description
 */
@RestController
public class AttributeGroupController {
    
    @Autowired
    private TypeAttributeGroupService attributeGroupService;

    @PostMapping("/attribute-group")
    public ResponseVo createGroup(@RequestBody AttributeGroupDTO attributeGroupDTO) {
        ResponseVo response = new ResponseVo<>();
        attributeGroupService.saveGroup(attributeGroupDTO);
        return response;
    }

    @DeleteMapping("/attribute-group/{id}")
    public ResponseVo<Object> deleteGroup(@PathVariable("id") Long id) {
        ResponseVo<Object> response = new ResponseVo<>();
        attributeGroupService.deleteGroup(id);
        return response;
    }

    @PutMapping("/attribute-group")
    public ResponseVo<Object> updateGroup(@RequestBody AttributeGroupDTO attributeGroupDTO) {
        ResponseVo<Object> response = new ResponseVo<>();
        attributeGroupService.saveGroup(attributeGroupDTO);
        return response;
    }

    @DeleteMapping("/attribute-group/attribute")
    public ResponseVo<Object> deleteAttributeOfGroup(@RequestBody AttributeGroupDTO attributeGroupDTO) {
        ResponseVo<Object> response = new ResponseVo<>();
        attributeGroupService.batchDelAttributesOfGroup(attributeGroupDTO.getLocalAttributeIds());
        return response;
    }

    @PutMapping("/attribute-group/change")
    public ResponseVo<Object> transferGroup(@RequestBody AttributeGroupDTO attributeGroupDTO) {
        ResponseVo<Object> response = new ResponseVo<>();
        attributeGroupService.changeGroupForAttributes(attributeGroupDTO.getLocalAttributeIds(), attributeGroupDTO.getGroupId(),attributeGroupDTO.getTypeId());
        return response;
    }
}
